import 'package:flutter/material.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/in_order_page_child_entity.dart';
import 'package:library_base/entities/warehouse_entity.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/colors.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/res/widget_generator.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/res/edge.dart';
import 'package:get/get.dart';
import 'package:library_base/widget/button/ink_bg_well.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:module_wms/page/incoming_orders/incoming_orders_controller.dart';

Widget buildSearchWidget(
    IncomingOrdersController asOrderController,
{
  ValueChanged<String>? onChanged,
  ValueChanged<String>? onSearch,
}
) {
  return Container(
    color: ThemeUtil.getTheme().colorScheme.secondary,
    height: 116.w,
    child: Row(
      children: <Widget>[
        Expanded(
          child: Container(
              alignment: Alignment.center,
              height: double.infinity,
              width: double.infinity,
              margin: EdgeInsets.only(left: 24.w, top: 24.w, bottom: 24.w),
              decoration: BoxDecoration(
                color: ThemeUtil.getTheme().secondaryBgColor(),
                borderRadius: const BorderRadius.all(Radius.circular(30.0)),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  gapW24,
                  LocalImage('common_search',
                      package: Constant.packLib(), width: 26.w, height: 26.w),
                  gapW18,
                  Expanded(
                    child: Container(
                      alignment: Alignment.center,
                      height: double.infinity,
                      width: double.infinity,
                      child: TextField(
                        onChanged: onChanged,
                        style: normalTextColor28,
                        autofocus: false,
                        controller: asOrderController.keyWorkSearchController,
                        textAlignVertical: TextAlignVertical.center,
                        decoration: InputDecoration(
                          focusedBorder: const OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 0, color: Colors.transparent)),
                          disabledBorder: const OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 0, color: Colors.transparent)),
                          enabledBorder: const OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 0, color: Colors.transparent)),
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 0),
                          border: InputBorder.none,
                          labelStyle: TextStyles.textNormal28,
                          hintText: MultiLanguage.pleaseEnterNumber.tr,
                          hintStyle: TextStyles.textSixthColor28,
                          suffixIcon:
                          asOrderController.keyWord.isNotEmpty
                              ? IconButton(
                            iconSize: 30.w,
                            icon: Icon(Icons.close,
                                color: Colours.gray_400, size: 40.w),
                            onPressed: () {
                              asOrderController.keyWorkSearchController.text = '';
                              asOrderController.keyWord.value = "";
                              asOrderController.update();
                            },
                          )
                              : gapZero,
                        ),
                      ),
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(right: 24.w),
                    child: LocalImage('wms_scan',
                        package: Constant.packWms(), width: 32.w, height: 32.w),
                  ),
                ],
              )),
        ),
        textInkBgWell(MultiLanguage.search.tr, onTap: (action) {
          onSearch?.call(action);
        })
      ],
    ),
  );
}

Widget buildItem(
  InOrderPageChildEntity taskEntity,
  int position, {
  Function(InOrderPageChildEntity taskEntity, int position)? toDetail,
}) {
  List<Widget> widgets = [];

  widgets.add(gapH24);

  ///第一行内容
  widgets.add(Container(
    padding: EdgeInsets.symmetric(horizontal: 24.w),
    child: SizedBox(
      width: double.infinity,
      child: Text(taskEntity.purchaseOrderNumber,
          style: normalTextColor28),
    ),
  ));
  widgets.add(gapH18);

  widgets.add(Container(
    padding: EdgeInsets.symmetric(horizontal: 24.w),
    child: Row(
      children: [
        Text("${MultiLanguage.warehouse.tr} : ", style: normalTextColor28),
        Expanded(
          child: Text(taskEntity.warehouseName.toString(),
              style: normalTextColor28),
        ),
      ],
    ),
  ));
  widgets.add(gapH18);

  widgets.add(Container(
    padding: EdgeInsets.symmetric(horizontal: 24.w),
    child: Row(
      children: [
        Text("${MultiLanguage.commodityQuantity.tr} : ", style: normalTextColor28),
        Expanded(
          child: Text(taskEntity.purchaseCount.toString(),
              style: normalTextColor28),
        ),
      ],
    ),
  ));

  widgets.add(gapH18);
  widgets.add(Container(
    padding: EdgeInsets.symmetric(horizontal: 24.w),
    child: Row(
      children: [
        Text("${MultiLanguage.creationTime.tr} : ", style: normalTextColor28),
        Text(taskEntity.createTime.toString(),
            style: normalTextColor28),
      ],
    ),
  ));

  widgets.add(gapH24);
  return GestureDetector(
    onTap: () {
      toDetail?.call(taskEntity,position);
    },
    child: roundWidget(
      margin: edgeLR24,
      decoration: rs8,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: widgets,
      ),
    ),
  );
}


Widget filterWell(
    {
      Function()? onTap,
    }) {
  return inkBgWell(
    child: Container(
        padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 24.w),
        child:
        LocalImage('admin_filter', package: Constant.packAdmin(), width: 38.w, height: 38.w)),
    onTap: () => onTap?.call(),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

